<?php

namespace App\Models;


class Note extends BaseModel
{
    protected $fillable = [
        'userId',
        'questionId',
        'title',
        'content',
        'status',
    ];

    protected $appends = ['knowledgeName', 'courseName', 'questionLibraryName'];

    public function getQuestionLibraryNameAttribute() {
        $name = null;
        if (!empty($this->qlId)) {
            $name = Qh_QuestionLibrary::where('id', $this->qlId)->value('name');
        }
        return $name;
    }

    public function getCourseNameAttribute() {
        $name = null;
        if (!empty($this->courseId)) {
            $name = Qh_Course::where('id', $this->courseId)->value('name');
        }

        return $name;
    }

    public function getKnowledgeNameAttribute() {
        $name = null;
        if (!empty($this->knowledgeId)) {
            $name = Qh_Knowledge::where('id', $this->knowledgeId)->value('name');
        }
        return $name;
    }


    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s'
    ];
}
